import { useEffect, useState } from "react";
import { CiHeart } from "react-icons/ci";

export default function DateTime({
  publishTimeProps,
  like,
}: {
  publishTimeProps: string;
  like: number;
}) {
  const [publishTime, setPublishTime] = useState(publishTimeProps);

  useEffect(() => {
    // 模拟获取文章发表时间
    setPublishTime(publishTime);
  }, [publishTime]);

  const showDateBasedOnRecord = (publishTime: string | number | Date) => {
    const date = new Date(publishTime);
    const year = date.getFullYear();
    const month = date.toLocaleString("en-US", { month: "long" });
    const day = date.getDate();
    return `${month} ${day} ${year} `;
  };
  return (
    <div className="flex items-center text-[#a6acb7] text-[0.875rem] leading-4 gap-2">
      <CiHeart className="text-[0.875rem] leading-4" />
      <span className="flex items-center">{like}</span>
      <span>{showDateBasedOnRecord(publishTime)}</span>
    </div>
  );
}
